package com.itheima.health.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.itheima.health.pojo.Menu;
import com.itheima.health.vo.MenuVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface MenuMapper extends BaseMapper<Menu> {

    @Select("SELECT id,name,path,icon " +
            "FROM t_menu tm,t_role_menu trm " +
            "WHERE tm.parentMenuId is null and tm.id = trm.menu_id and trm.role_id=#{roleId}")
    List<MenuVO> getParentMenu(@Param("roleId") Integer roleId);

    @Select("SELECT id,name,linkUrl,path " +
            "FROM t_menu tm,t_role_menu trm " +
            "WHERE tm.parentMenuId=#{parentMenuId} and tm.id = trm.menu_id and trm.role_id=#{roleId}")
    List<MenuVO> getChildrenByParentMenuId(@Param("parentMenuId") Integer parentMenuId, @Param("roleId") Integer roleId);
}
